package com.seqb.common.task;

import com.seqb.utils.DateUtils;
import com.seqb.utils.JsonUtils;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author lilinshen
 * @title 阳光林厂定时任务
 * @description 请填写相关描述
 * @date 2020/3/2
 */
@Component
public class YangGuangLinChangJob implements Job {
    private static final Logger LOGGER = LoggerFactory.getLogger(YangGuangLinChangJob.class);

    @Autowired
    private RestTemplate restTemplate;

    @Override
    public void execute(JobExecutionContext context) {
        try {
            LOGGER.info("阳光林厂任务开始------lls-----" + DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
            //每天签到
            boolean flag = DailyQianDao();
            Thread.sleep(10000);
            if (flag) {
                //浇水
                jiaoShui();
                Thread.sleep(10000);

                //领红包
                lingHongBao();
                Thread.sleep(10000);
            }
            //先领水（5分钟一次）
            LingQuShui();
            Thread.sleep(10000);

            //浇水
            jiaoShui();
            Thread.sleep(10000);

            //领红包
            lingHongBao();
            Thread.sleep(10000);

            //领漂浮红包
            lingPiaoFuHongBao();
            LOGGER.info("阳光林厂任务结束------lls-----" + DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
            Thread.sleep(10000);


            LOGGER.info("阳光林厂任务开始------ydn-----" + DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
            //每天签到
            flag = DailyQianDao1();
            Thread.sleep(10000);
            if (flag) {
                //浇水
                jiaoShui1();
                Thread.sleep(10000);

                //领红包
                lingHongBao1();
                Thread.sleep(10000);
            }
            //先领水（5分钟一次）
            LingQuShui1();
            Thread.sleep(10000);

            //浇水
            jiaoShui1();
            Thread.sleep(10000);

            //领红包
            lingHongBao1();
            Thread.sleep(10000);

            //领漂浮红包
            lingPiaoFuHongBao1();
            Thread.sleep(10000);
            LOGGER.info("阳光林厂任务结束------ydn-----" + DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 领水操作
     */
    public boolean LingQuShui() {
        try {
            String requestUrl = "https://xcx.szlzyd.com/r/api/task/minute/wxb167b5df9d2b9e45/v=030101_oqoy55Vz_E7RUXR27i5j-IIHKwY0";
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_JSON);
            HttpMethod httpMethod = HttpMethod.POST;
            Map<String, Object> paramsMap = new HashMap<>();
            Map<String, Object> commonMap = new HashMap<>();
            Map<String, Object> itemMap = new HashMap<>();
            commonMap.put("appId", "wxb167b5df9d2b9e45");
            commonMap.put("productId", 110);
            commonMap.put("productName", "阳光林厂");
            commonMap.put("openId", "oqoy55Vz_E7RUXR27i5j-IIHKwY0");
            commonMap.put("customKey", "3BA3A09386D6D5CF865F");
            commonMap.put("unionId", "");
            commonMap.put("uuid", "ded59d05-f1fe-415c-8757-f4cc9d4b61a8");
            commonMap.put("platform", "windows");
            commonMap.put("version", "030101");
            paramsMap.put("b", commonMap);
            itemMap.put("bonusesTypeIds", new Long[]{2702L});
            paramsMap.put("o", itemMap);
            HttpEntity httpEntity = new HttpEntity(JsonUtils.beanToJson(paramsMap), headers);
            ResponseEntity<String> responseEntity = restTemplate.exchange(requestUrl, httpMethod, httpEntity, String.class);
            HttpStatus status = responseEntity.getStatusCode();
            if (status.equals(HttpStatus.OK)) {
                String entityBody = responseEntity.getBody();
                entityBody = new String(entityBody.getBytes("ISO-8859-1"), "utf-8");
                LOGGER.info("领水操作：" + entityBody);
                Map<String, Object> entityMap = JsonUtils.jsonToMap(entityBody);
                if (null != entityMap.get("code") && "1".equals(String.valueOf(entityMap.get("code")))) {
                    return true;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 浇水操作
     */
    public boolean jiaoShui() {
        try {
            String requestUrl = "https://xcx.szlzyd.com/r/api/io110/watering/wxb167b5df9d2b9e45/v=030101_oqoy55Vz_E7RUXR27i5j-IIHKwY0";
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_JSON);
            HttpMethod httpMethod = HttpMethod.POST;
            Map<String, Object> paramsMap = new HashMap<>();
            Map<String, Object> commonMap = new HashMap<>();
            Map<String, Object> itemMap = new HashMap<>();
            commonMap.put("appId", "wxb167b5df9d2b9e45");
            commonMap.put("productId", 110);
            commonMap.put("productName", "阳光林厂");
            commonMap.put("openId", "oqoy55Vz_E7RUXR27i5j-IIHKwY0");
            commonMap.put("customKey", "3BA3A09386D6D5CF865F");
            commonMap.put("unionId", "");
            commonMap.put("uuid", "ded59d05-f1fe-415c-8757-f4cc9d4b61a8");
            commonMap.put("platform", "windows");
            commonMap.put("version", "030101");
            paramsMap.put("b", commonMap);
            itemMap.put("bonusesTypeId", 2711);
            paramsMap.put("o", itemMap);
            HttpEntity httpEntity = new HttpEntity(JsonUtils.beanToJson(paramsMap), headers);
            ResponseEntity<String> responseEntity = restTemplate.exchange(requestUrl, httpMethod, httpEntity, String.class);
            HttpStatus status = responseEntity.getStatusCode();
            if (status.equals(HttpStatus.OK)) {
                String entityBody = responseEntity.getBody();
                entityBody = new String(entityBody.getBytes("ISO-8859-1"), "utf-8");
                LOGGER.info("浇水操作：" + entityBody);
                Map<String, Object> entityMap = JsonUtils.jsonToMap(entityBody);
                if (null != entityMap.get("code") && "1".equals(String.valueOf(entityMap.get("code")))) {
                    return true;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 领红包操作
     */
    public boolean lingHongBao() {
        try {
            String requestUrl = "https://xcx.szlzyd.com/r/api/io110/openRedEnvelopes/wxb167b5df9d2b9e45/v=030101_oqoy55Vz_E7RUXR27i5j-IIHKwY0";
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_JSON);
            HttpMethod httpMethod = HttpMethod.POST;
            Map<String, Object> paramsMap = new HashMap<>();
            Map<String, Object> commonMap = new HashMap<>();
            Map<String, Object> itemMap = new HashMap<>();
            commonMap.put("appId", "wxb167b5df9d2b9e45");
            commonMap.put("productId", 110);
            commonMap.put("productName", "阳光林厂");
            commonMap.put("openId", "oqoy55Vz_E7RUXR27i5j-IIHKwY0");
            commonMap.put("customKey", "3BA3A09386D6D5CF865F");
            commonMap.put("unionId", "");
            commonMap.put("uuid", "ded59d05-f1fe-415c-8757-f4cc9d4b61a8");
            commonMap.put("platform", "windows");
            commonMap.put("version", "030101");
            paramsMap.put("b", commonMap);
            itemMap.put("bonusesTypeId", 2712);
            paramsMap.put("o", itemMap);
            HttpEntity httpEntity = new HttpEntity(JsonUtils.beanToJson(paramsMap), headers);
            ResponseEntity<String> responseEntity = restTemplate.exchange(requestUrl, httpMethod, httpEntity, String.class);
            HttpStatus status = responseEntity.getStatusCode();
            if (status.equals(HttpStatus.OK)) {
                String entityBody = responseEntity.getBody();
                entityBody = new String(entityBody.getBytes("ISO-8859-1"), "utf-8");
                LOGGER.info("领红包操作：" + entityBody);
                Map<String, Object> entityMap = JsonUtils.jsonToMap(entityBody);
                if (null != entityMap.get("code") && "1".equals(String.valueOf(entityMap.get("code")))) {
                    return true;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 领漂浮红包操作
     */
    public boolean lingPiaoFuHongBao() {
        try {
            String requestUrl = "https://xcx.szlzyd.com/r/api/task/minute/wxb167b5df9d2b9e45/v=030101_oqoy55Vz_E7RUXR27i5j-IIHKwY0";
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_JSON);
            HttpMethod httpMethod = HttpMethod.POST;
            Map<String, Object> paramsMap = new HashMap<>();
            Map<String, Object> commonMap = new HashMap<>();
            Map<String, Object> itemMap = new HashMap<>();
            commonMap.put("appId", "wxb167b5df9d2b9e45");
            commonMap.put("productId", 110);
            commonMap.put("productName", "阳光林厂");
            commonMap.put("openId", "oqoy55Vz_E7RUXR27i5j-IIHKwY0");
            commonMap.put("customKey", "3BA3A09386D6D5CF865F");
            commonMap.put("unionId", "");
            commonMap.put("uuid", "ded59d05-f1fe-415c-8757-f4cc9d4b61a8");
            commonMap.put("platform", "windows");
            commonMap.put("version", "030101");
            paramsMap.put("b", commonMap);
            itemMap.put("bonusesTypeIds", new Long[]{2697L});
            paramsMap.put("o", itemMap);
            HttpEntity httpEntity = new HttpEntity(JsonUtils.beanToJson(paramsMap), headers);
            ResponseEntity<String> responseEntity = restTemplate.exchange(requestUrl, httpMethod, httpEntity, String.class);
            HttpStatus status = responseEntity.getStatusCode();
            if (status.equals(HttpStatus.OK)) {
                String entityBody = responseEntity.getBody();
                entityBody = new String(entityBody.getBytes("ISO-8859-1"), "utf-8");
                LOGGER.info("领漂浮红包操作：" + entityBody);
                Map<String, Object> entityMap = JsonUtils.jsonToMap(entityBody);
                if (null != entityMap.get("code") && "1".equals(String.valueOf(entityMap.get("code")))) {
                    return true;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 每天签到操作
     */
    public boolean DailyQianDao() {
        try {
            String requestUrl = "https://xcx.szlzyd.com/r/api/sign/serialSign/wxb167b5df9d2b9e45/v=030101_oqoy55Vz_E7RUXR27i5j-IIHKwY0";
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_JSON);
            HttpMethod httpMethod = HttpMethod.POST;
            Map<String, Object> paramsMap = new HashMap<>();
            Map<String, Object> commonMap = new HashMap<>();
            Map<String, Object> itemMap = new HashMap<>();
            commonMap.put("appId", "wxb167b5df9d2b9e45");
            commonMap.put("productId", 110);
            commonMap.put("productName", "阳光林厂");
            commonMap.put("openId", "oqoy55Vz_E7RUXR27i5j-IIHKwY0");
            commonMap.put("customKey", "3BA3A09386D6D5CF865F");
            commonMap.put("unionId", "");
            commonMap.put("uuid", "ded59d05-f1fe-415c-8757-f4cc9d4b61a8");
            commonMap.put("platform", "windows");
            commonMap.put("version", "030101");
            paramsMap.put("b", commonMap);
            paramsMap.put("o", itemMap);
            HttpEntity httpEntity = new HttpEntity(JsonUtils.beanToJson(paramsMap), headers);
            ResponseEntity<String> responseEntity = restTemplate.exchange(requestUrl, httpMethod, httpEntity, String.class);
            HttpStatus status = responseEntity.getStatusCode();
            if (status.equals(HttpStatus.OK)) {
                String entityBody = responseEntity.getBody();
                entityBody = new String(entityBody.getBytes("ISO-8859-1"), "utf-8");
                LOGGER.info("每天签到操作：" + entityBody);
                Map<String, Object> entityMap = JsonUtils.jsonToMap(entityBody);
                if (null != entityMap.get("code") && "1".equals(String.valueOf(entityMap.get("code")))) {
                    return true;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 领水操作
     */
    public boolean LingQuShui1() {
        try {
            String requestUrl = "https://xcx.szlzyd.com/r/api/task/minute/wxb167b5df9d2b9e45/v=030101_oqoy55ZeVo84ovymwl7Zib2OMero";
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_JSON);
            HttpMethod httpMethod = HttpMethod.POST;
            Map<String, Object> paramsMap = new HashMap<>();
            Map<String, Object> commonMap = new HashMap<>();
            Map<String, Object> itemMap = new HashMap<>();
            commonMap.put("appId", "wxb167b5df9d2b9e45");
            commonMap.put("productId", 110);
            commonMap.put("productName", "阳光林厂");
            commonMap.put("openId", "oqoy55ZeVo84ovymwl7Zib2OMero");
            commonMap.put("customKey", "D6B08851D06D7B0BC87A");
            commonMap.put("unionId", "");
            commonMap.put("uuid", "396e4ac7-3dfc-4675-9f0a-0eb26e4fff5e");
            commonMap.put("platform", "windows");
            commonMap.put("version", "030101");
            paramsMap.put("b", commonMap);
            itemMap.put("bonusesTypeIds", new Long[]{2702L});
            paramsMap.put("o", itemMap);
            HttpEntity httpEntity = new HttpEntity(JsonUtils.beanToJson(paramsMap), headers);
            ResponseEntity<String> responseEntity = restTemplate.exchange(requestUrl, httpMethod, httpEntity, String.class);
            HttpStatus status = responseEntity.getStatusCode();
            if (status.equals(HttpStatus.OK)) {
                String entityBody = responseEntity.getBody();
                entityBody = new String(entityBody.getBytes("ISO-8859-1"), "utf-8");
                LOGGER.info("领水操作：" + entityBody);
                Map<String, Object> entityMap = JsonUtils.jsonToMap(entityBody);
                if (null != entityMap.get("code") && "1".equals(String.valueOf(entityMap.get("code")))) {
                    return true;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 浇水操作
     */
    public boolean jiaoShui1() {
        try {
            String requestUrl = "https://xcx.szlzyd.com/r/api/io110/watering/wxb167b5df9d2b9e45/v=030101_oqoy55ZeVo84ovymwl7Zib2OMero";
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_JSON);
            HttpMethod httpMethod = HttpMethod.POST;
            Map<String, Object> paramsMap = new HashMap<>();
            Map<String, Object> commonMap = new HashMap<>();
            Map<String, Object> itemMap = new HashMap<>();
            commonMap.put("appId", "wxb167b5df9d2b9e45");
            commonMap.put("productId", 110);
            commonMap.put("productName", "阳光林厂");
            commonMap.put("openId", "oqoy55ZeVo84ovymwl7Zib2OMero");
            commonMap.put("customKey", "D6B08851D06D7B0BC87A");
            commonMap.put("unionId", "");
            commonMap.put("uuid", "396e4ac7-3dfc-4675-9f0a-0eb26e4fff5e");
            commonMap.put("platform", "windows");
            commonMap.put("version", "030101");
            paramsMap.put("b", commonMap);
            itemMap.put("bonusesTypeId", 2711);
            paramsMap.put("o", itemMap);
            HttpEntity httpEntity = new HttpEntity(JsonUtils.beanToJson(paramsMap), headers);
            ResponseEntity<String> responseEntity = restTemplate.exchange(requestUrl, httpMethod, httpEntity, String.class);
            HttpStatus status = responseEntity.getStatusCode();
            if (status.equals(HttpStatus.OK)) {
                String entityBody = responseEntity.getBody();
                entityBody = new String(entityBody.getBytes("ISO-8859-1"), "utf-8");
                LOGGER.info("浇水操作：" + entityBody);
                Map<String, Object> entityMap = JsonUtils.jsonToMap(entityBody);
                if (null != entityMap.get("code") && "1".equals(String.valueOf(entityMap.get("code")))) {
                    return true;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 领红包操作
     */
    public boolean lingHongBao1() {
        try {
            String requestUrl = "https://xcx.szlzyd.com/r/api/io110/openRedEnvelopes/wxb167b5df9d2b9e45/v=030101_oqoy55ZeVo84ovymwl7Zib2OMero";
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_JSON);
            HttpMethod httpMethod = HttpMethod.POST;
            Map<String, Object> paramsMap = new HashMap<>();
            Map<String, Object> commonMap = new HashMap<>();
            Map<String, Object> itemMap = new HashMap<>();
            commonMap.put("appId", "wxb167b5df9d2b9e45");
            commonMap.put("productId", 110);
            commonMap.put("productName", "阳光林厂");
            commonMap.put("openId", "oqoy55ZeVo84ovymwl7Zib2OMero");
            commonMap.put("customKey", "D6B08851D06D7B0BC87A");
            commonMap.put("unionId", "");
            commonMap.put("uuid", "396e4ac7-3dfc-4675-9f0a-0eb26e4fff5e");
            commonMap.put("platform", "windows");
            commonMap.put("version", "030101");
            paramsMap.put("b", commonMap);
            itemMap.put("bonusesTypeId", 2712);
            paramsMap.put("o", itemMap);
            HttpEntity httpEntity = new HttpEntity(JsonUtils.beanToJson(paramsMap), headers);
            ResponseEntity<String> responseEntity = restTemplate.exchange(requestUrl, httpMethod, httpEntity, String.class);
            HttpStatus status = responseEntity.getStatusCode();
            if (status.equals(HttpStatus.OK)) {
                String entityBody = responseEntity.getBody();
                entityBody = new String(entityBody.getBytes("ISO-8859-1"), "utf-8");
                LOGGER.info("领红包操作：" + entityBody);
                Map<String, Object> entityMap = JsonUtils.jsonToMap(entityBody);
                if (null != entityMap.get("code") && "1".equals(String.valueOf(entityMap.get("code")))) {
                    return true;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 领漂浮红包操作
     */
    public boolean lingPiaoFuHongBao1() {
        try {
            String requestUrl = "https://xcx.szlzyd.com/r/api/task/minute/wxb167b5df9d2b9e45/v=030101_oqoy55ZeVo84ovymwl7Zib2OMero";
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_JSON);
            HttpMethod httpMethod = HttpMethod.POST;
            Map<String, Object> paramsMap = new HashMap<>();
            Map<String, Object> commonMap = new HashMap<>();
            Map<String, Object> itemMap = new HashMap<>();
            commonMap.put("appId", "wxb167b5df9d2b9e45");
            commonMap.put("productId", 110);
            commonMap.put("productName", "阳光林厂");
            commonMap.put("openId", "oqoy55ZeVo84ovymwl7Zib2OMero");
            commonMap.put("customKey", "D6B08851D06D7B0BC87A");
            commonMap.put("unionId", "");
            commonMap.put("uuid", "396e4ac7-3dfc-4675-9f0a-0eb26e4fff5e");
            commonMap.put("platform", "windows");
            commonMap.put("version", "030101");
            paramsMap.put("b", commonMap);
            itemMap.put("bonusesTypeIds", new Long[]{2697L});
            paramsMap.put("o", itemMap);
            HttpEntity httpEntity = new HttpEntity(JsonUtils.beanToJson(paramsMap), headers);
            ResponseEntity<String> responseEntity = restTemplate.exchange(requestUrl, httpMethod, httpEntity, String.class);
            HttpStatus status = responseEntity.getStatusCode();
            if (status.equals(HttpStatus.OK)) {
                String entityBody = responseEntity.getBody();
                entityBody = new String(entityBody.getBytes("ISO-8859-1"), "utf-8");
                LOGGER.info("领漂浮红包操作：" + entityBody);
                Map<String, Object> entityMap = JsonUtils.jsonToMap(entityBody);
                if (null != entityMap.get("code") && "1".equals(String.valueOf(entityMap.get("code")))) {
                    return true;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 每天签到操作
     */
    public boolean DailyQianDao1() {
        try {
            String requestUrl = "https://xcx.szlzyd.com/r/api/sign/serialSign/wxb167b5df9d2b9e45/v=030101_oqoy55ZeVo84ovymwl7Zib2OMero";
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_JSON);
            HttpMethod httpMethod = HttpMethod.POST;
            Map<String, Object> paramsMap = new HashMap<>();
            Map<String, Object> commonMap = new HashMap<>();
            Map<String, Object> itemMap = new HashMap<>();
            commonMap.put("appId", "wxb167b5df9d2b9e45");
            commonMap.put("productId", 110);
            commonMap.put("productName", "阳光林厂");
            commonMap.put("openId", "oqoy55ZeVo84ovymwl7Zib2OMero");
            commonMap.put("customKey", "D6B08851D06D7B0BC87A");
            commonMap.put("unionId", "");
            commonMap.put("uuid", "396e4ac7-3dfc-4675-9f0a-0eb26e4fff5e");
            commonMap.put("platform", "windows");
            commonMap.put("version", "030101");
            paramsMap.put("b", commonMap);
            paramsMap.put("o", itemMap);
            HttpEntity httpEntity = new HttpEntity(JsonUtils.beanToJson(paramsMap), headers);
            ResponseEntity<String> responseEntity = restTemplate.exchange(requestUrl, httpMethod, httpEntity, String.class);
            HttpStatus status = responseEntity.getStatusCode();
            if (status.equals(HttpStatus.OK)) {
                String entityBody = responseEntity.getBody();
                entityBody = new String(entityBody.getBytes("ISO-8859-1"), "utf-8");
                LOGGER.info("每天签到操作：" + entityBody);
                Map<String, Object> entityMap = JsonUtils.jsonToMap(entityBody);
                if (null != entityMap.get("code") && "1".equals(String.valueOf(entityMap.get("code")))) {
                    return true;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
}
